<?php
// 测试配置读取
namespace think\admin;

use app\checkin\model\Setting as SettingModel;

// 引入框架
require __DIR__ . '/vendor/autoload.php';

// 创建应用
$app = new \think\App();
$app->initialize();

echo "=== 测试系统配置读取 ===\n\n";

try {
    $config = SettingModel::getConfig(0);
    
    echo "1. 配置对象类型：" . get_class($config) . "\n";
    echo "2. 配置是否为空：" . ($config->isEmpty() ? '是' : '否') . "\n\n";
    
    echo "3. unit_minutes: " . var_export($config->unit_minutes, true) . " (类型: " . gettype($config->unit_minutes) . ")\n";
    echo "4. unit_points: " . var_export($config->unit_points, true) . " (类型: " . gettype($config->unit_points) . ")\n";
    echo "5. time_slots 原始值: " . var_export($config->time_slots, true) . " (类型: " . gettype($config->time_slots) . ")\n\n";
    
    // 测试获取 time_slots
    $timeSlots = $config->time_slots;
    echo "6. time_slots 赋值后类型: " . gettype($timeSlots) . "\n";
    
    if (is_array($timeSlots)) {
        echo "7. time_slots 是数组，元素数量: " . count($timeSlots) . "\n";
        if (count($timeSlots) > 0) {
            echo "8. time_slots 内容:\n";
            foreach ($timeSlots as $i => $slot) {
                echo "   [$i] " . json_encode($slot, JSON_UNESCAPED_UNICODE) . "\n";
            }
        } else {
            echo "8. time_slots 是空数组\n";
        }
    } else {
        echo "7. time_slots 不是数组！\n";
        echo "8. time_slots 值: " . var_export($timeSlots, true) . "\n";
    }
    
    echo "\n9. 测试 JSON 编码:\n";
    try {
        $json = json_encode($timeSlots, JSON_UNESCAPED_UNICODE);
        echo "   成功: " . $json . "\n";
    } catch (\Exception $e) {
        echo "   失败: " . $e->getMessage() . "\n";
    }
    
    echo "\n10. 配置完整数组:\n";
    print_r($config->toArray());
    
} catch (\Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "文件: " . $e->getFile() . "\n";
    echo "行号: " . $e->getLine() . "\n";
    echo "堆栈:\n" . $e->getTraceAsString() . "\n";
}

echo "\n=== 测试完成 ===\n";

